home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / util / wb / ProcessIcon.lha / Source / ProcessIcon.c
Encoding:
C/C++ Source or Header  |  1999-12-06  |  27.1 KB  |  720 lines

  1. #define NAME     "ProcessIcon"
  2. #define REVISION "19"
  3.  
  4. /* Programmheader
  5.  
  6.         Name:           ProcessIcon
  7.         Author:         SDI
  8.         Distribution:   PD
  9.         Description:    processes .info files
  10.         Compileropts:   -
  11.         Linkeropts:     -l amiga
  12.  
  13.  1.0   01.93.97 : first version
  14.  1.1   03.03.97 : options KILLSTACKSIZE, KILLDEFTOOL, VIEW
  15.  1.2   05.03.97 : added SIT and CIT options
  16.  1.3   29.03.97 : not existing TO produces icon
  17.  1.4   13.06.97 : lots of changes, renamed from CopyIconImage
  18.  1.5   14.06.97 : added more data to VIEW option
  19.  1.6   01.07.97 : fixed problem with DrawerData
  20.  1.7   09.11.97 : added UNSNAP function
  21.  1.8   05.02.98 : IMGSRC became REFICON, added CII instead of autocopy
  22.  1.9   01.09.98 : better VIEW output
  23.  1.10  08.05.99 : added REMAP option
  24.  1.11  21.09.99 : KTT removes entry totally
  25.  1.12  11.10.99 : add SSS option
  26.  1.13  05.11.99 : added NewIcon support
  27.  1.14  09.11.99 : added OS3.5 support, better source, removed global variables,
  28.     program got multi-reentrant
  29.  1.15  10.11.99 : little bug fix
  30.  1.16  15.11.99 : added MAKECI
  31.  1.17  21.11.99 : bug-fix
  32.  1.18  27.11.99 : added SHOWTYPE
  33.  1.19  29.11.99 : Fixed II2CI, SHOWTYPE
  34. */
  35.  
  36. #include <proto/dos.h>
  37. #include <proto/icon.h>
  38. #include <proto/exec.h>
  39. #include <proto/graphics.h>
  40. #include <exec/memory.h>
  41. #include <workbench/icon.h>
  42. #define SDI_TO_ANSI
  43. #include "SDI_ASM_STD_protos.h"
  44. #include "SDI_defines.h"
  45.  
  46. #define PARAM (STRPTR)  "ICON/A,REFICON,VIEW/S,OPT=OPTIMIZE/S,"         \
  47.                         "US=UNSNAP/S,REMAP/S,SHOWTYPE/S,"               \
  48.                         "NI2CI/S,MWB2CI/S,II2CI/S,MAKECI/S,"            \
  49.                         "SBP=SETBITPLANES/N,SDT=SETDEFTOOL,"            \
  50.                         "SIT=SETICONTYPE,SSS=SETSTACKSIZE/N,"           \
  51.                         "ST1=SETTRANSPARENT1/N,ST2=SETTRANSPARENT2/N,"    \
  52.                         "SXP=SETXPOS/N,SYP=SETYPOS/N,"                  \
  53.                         "KCI=KILLCOLORICON/S,"                          \
  54.                         "KDD=KILLDRAWERDATA/S,KDT=KILLDEFTOOL/S,"       \
  55.                         "KII=KILLICONIMAGE/S,KNI=KILLNEWICON/S,"        \
  56.                         "KSS=KILLSTACKSIZE/S,KTT=KILLTOOLTYPES/S,"      \
  57.                         "CCI=COPYCOLORICON/S,"                          \
  58.                         "CDD=COPYDRAWERDATA/S,CDT=COPYDEFTOOL/S,"       \
  59.                         "CII=COPYICONIMAGE/S,CIT=COPYICONTYPE/S,"       \
  60.                         "CNI=COPYNEWICON/S,CSS=COPYSTACKSIZE/S,"        \
  61.                         "CTT=COPYTOOLTYPES/S"
  62. struct Args {
  63.     STRPTR      icon;
  64.     STRPTR      reficon;
  65.     ULONG       view;
  66.     ULONG       optimize;
  67.     ULONG       unsnap;
  68.     ULONG       remap;
  69.     ULONG    showtype;
  70.     ULONG       ni2ci;
  71.     ULONG       mwb2ci;
  72.     ULONG       ii2ci;
  73.     ULONG       makeci;
  74.     ULONG *     setbitplanes;
  75.     STRPTR      setdeftool;
  76.     STRPTR      seticontype;
  77.     ULONG *     setstacksize;
  78.     LONG *    settransparent1;
  79.     LONG *      settransparent2;
  80.     ULONG *     setxpos;
  81.     ULONG *     setypos;
  82.     ULONG       killcoloricon;
  83.     ULONG       killdrawerdata;
  84.     ULONG       killdeftool;
  85.     ULONG       killiconimage;
  86.     ULONG       killnewicon;
  87.     ULONG       killstacksize;
  88.     ULONG       killtooltypes;
  89.     ULONG       copycoloricon;
  90.     ULONG       copydrawerdata;
  91.     ULONG       copydeftool;
  92.     ULONG       copyiconimage;
  93.     ULONG       copyicontype;
  94.     ULONG       copynewicon;
  95.     ULONG       copystacksize;
  96.     ULONG       copytooltypes;
  97. };
  98.  
  99. const STRPTR IconTypeRecog[] = {0, "Disk", "Drawer", "Tool", "Project", "Garbage", "Device", "Kick", "AppIcon"};
  100. const UBYTE NewIconTXT[] = "*** DON'T EDIT THE FOLLOWING LINES!! ***";
  101. const UWORD KIIData[] = {0xF000,0xF000,0xF000,0xF000};
  102. const struct Image KIIImage = {0, 0, 4, 4, 1, (UWORD *) &KIIData, 1, 0, 0};
  103. const UBYTE MagicWBPalette[8 * 3] = { 0x96,0x96,0x96, 0x00,0x00,0x00, 0xFF,0xFF,0xFF, 0x3D,0x65,0xA2,
  104.       0x79,0x79,0x79, 0xAE,0xAE,0xAE, 0xAA,0x92,0x7D, 0xFF,0xAA,0x96};
  105. const UBYTE Default8Palette[8 * 3] = { 0xAA,0xAA,0xAA, 0x00,0x00,0x00, 0xFF,0xFF,0xFF, 0x65,0x8A,0xBA,
  106.       0xEF,0x45,0x45, 0x55,0xDF,0x55, 0x00,0x45,0xDF, 0xEF,0x9A,0x00};
  107.  
  108. static void RemapImage(struct Image *im)
  109. {
  110.   ULONG w, i, j, k, d;
  111.   UWORD *ptr;
  112.  
  113.   w = (im->Width+15)>>4; /* divide by 16 */
  114.   ptr = im->ImageData;
  115.  
  116.   if(im->Depth == 1)
  117.   {
  118.     for(i = 0; i < im->Height; ++i)
  119.     {
  120.       for(j = 0; j < w; ++j)
  121.         ptr[i*w + j] ^= 0xFFFF;
  122.       if((k = (w<<4) - im->Width))
  123.       {
  124.         /* clear last unused bits */
  125.         ptr[i*w + j - 1] &= (0xFFFF >> k) << k;
  126.       }
  127.     }
  128.   }
  129.   else
  130.   {
  131.     for(i = 0; i < im->Height; ++i)
  132.     {
  133.       for(j = 0; j < w; ++j)
  134.       {
  135.         k = ptr[i*w + j] ^ ptr[(im->Height + i)*w + j];
  136.         for(d = 2; d < im->Depth; ++d)
  137.           k &= (~ptr[(im->Height*d +i)*w + j]);
  138.         ptr[i*w + j] ^= k;
  139.         ptr[(im->Height + i)*w + j] ^= k;
  140.       }
  141.       if((k = (w<<4) - im->Width))
  142.       {
  143.         /* clear last unused bits */
  144.         ptr[i*w + j - 1] &= (0xFFFF >> k) << k;
  145.         ptr[(im->Height + i)*w + j - 1] &= (0xFFFF >> k) << k;
  146.       }
  147.     }
  148.   }
  149. }
  150.  
  151. #define TESTGROUP(a, b, c)      if((a && (b || c)) || (b && c)) ++argerr
  152.  
  153. #define TYPE_STANDARD   0
  154. #define TYPE_NEWICON    1
  155. #define TYPE_NEWICON35  2
  156. #define TYPE_OS35       3
  157. #define TYPE_BOTHCOLOR  4
  158.  
  159. ULONG dowork(struct Args *args, struct Library *IconBase, ULONG os35mode)
  160. {
  161.   ULONG ret = RETURN_FAIL, s;
  162.   struct DiskObject *dobj;
  163.  
  164.   if((dobj = (os35mode ? GetIconTags(args->icon,
  165.   ICONGETA_FailIfUnavailable, FALSE, ICONGETA_GetPaletteMappedIcon, FALSE, TAG_DONE) :
  166.   GetDiskObjectNew(args->icon))))
  167.   {
  168.     struct DiskObject *dobjdrw; 
  169.     if((dobjdrw = GetDefDiskObject(WBDRAWER)))
  170.     {
  171.       struct DiskObject *dobjsrc = 0;
  172.  
  173.       if(!args->reficon || (dobjsrc = (os35mode ?
  174.       GetIconTags(args->reficon, ICONGETA_GetPaletteMappedIcon, FALSE, TAG_DONE) : GetDiskObject(args->reficon))))
  175.       {
  176.         STRPTR *tooltypes;
  177.         UBYTE *imageBuffer[2] = {0, 0};
  178.         
  179.         if((tooltypes = (STRPTR *) AllocVec(1000*sizeof(STRPTR), MEMF_CLEAR)))
  180.         {
  181.           ULONG type = TYPE_STANDARD;
  182.           STRPTR *tt, t, t2;
  183.  
  184.           if((tt = (STRPTR *) dobj->do_ToolTypes))
  185.           {
  186.             while(*tt)
  187.             {
  188.               if((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT))
  189.                 type = TYPE_NEWICON;
  190.               ++tt;
  191.             }
  192.           }
  193.  
  194.           if(os35mode)
  195.           {
  196.             LONG p = 0, n = 0;
  197.           
  198.             IconControl(dobj, ICONCTRLA_IsPaletteMapped, &p, ICONCTRLA_IsNewIcon, &n, TAG_DONE);
  199.             if(p) type = TYPE_OS35;
  200.             if(n) type = TYPE_NEWICON35;
  201.             if(p && n) type = TYPE_BOTHCOLOR;
  202.           }
  203.  
  204.       if(args->makeci)
  205.       {
  206.         switch(type)
  207.         {
  208.         case TYPE_STANDARD: args->ii2ci = 1; break;
  209.         case TYPE_NEWICON: case TYPE_NEWICON35: args->ni2ci = 1; /* no break */
  210.         case TYPE_BOTHCOLOR: args->killnewicon = 1; break;
  211.         }
  212.       }
  213.  
  214.       if(args->showtype)
  215.       {
  216.             switch(type)
  217.             {
  218.               case TYPE_BOTHCOLOR: t = "OS3.5 + NewIcon"; break;
  219.               case TYPE_NEWICON: case TYPE_NEWICON35: t = "NewIcon"; break;
  220.               case TYPE_OS35: t = "OS3.5 Icon"; break;
  221.               default: t = "Standard"; break;
  222.             }
  223.             Printf("%-15s - %s\n", t, args->icon);
  224.             ret = RETURN_OK;
  225.       }
  226.           else if(args->view)
  227.           {
  228.             switch(type)
  229.             {
  230.               case TYPE_BOTHCOLOR: t = "OS3.5 + NewIcon"; break;
  231.               case TYPE_NEWICON: case TYPE_NEWICON35: t = "NewIcon"; break;
  232.               case TYPE_OS35: t = "OS3.5 Icon"; break;
  233.               default: t = "Standard"; break;
  234.             }
  235.  
  236.             if(type == TYPE_NEWICON)
  237.             {
  238.               t2 = "YES, NEWICON";
  239.  
  240.               if((**dobj->do_ToolTypes == ' ') && *(dobj->do_ToolTypes[1]) &&
  241.               !strcmp(dobj->do_ToolTypes[1], (STRPTR) NewIconTXT))
  242.                 t2 = "YES - EMPTY, NEWICON";
  243.             }
  244.             else if(type == TYPE_NEWICON35 || type == TYPE_BOTHCOLOR)
  245.             {
  246.               t2 = "YES, NEWICON";
  247.  
  248.               if(!(*dobj->do_ToolTypes))
  249.                 t2 = "YES - EMPTY, NEWICON";
  250.             }
  251.             else if(dobj->do_ToolTypes)
  252.             {
  253.               if(!(*dobj->do_ToolTypes))
  254.                 t2 = "YES - EMPTY";
  255.               else
  256.                 t2 = "YES";
  257.             }
  258.             else
  259.               t2 = "NO";
  260.  
  261.             Printf("Name: %s\nType: %s\n  SS: %ld\n  IT: %s\n  BP: %ld,%ld\n  SZ: ",
  262.               args->icon, t, dobj->do_StackSize, IconTypeRecog[dobj->do_Type],
  263.               ((struct Image *)dobj->do_Gadget.GadgetRender)->Depth,
  264.               (dobj->do_Gadget.SelectRender ?
  265.               ((struct Image *)dobj->do_Gadget.SelectRender)->Depth : 0));
  266.             Printf(dobj->do_CurrentX == NO_ICON_POSITION ? "NOPOS" : "x=%3ld",
  267.               dobj->do_CurrentX);
  268.             Printf(dobj->do_CurrentY == NO_ICON_POSITION ? ", NOPOS" : ", y=%3ld",
  269.               dobj->do_CurrentY);
  270.             Printf(", w=%3ld, h=%3ld\n  DT: (%s) %s\n",
  271.               dobj->do_Gadget.Width, dobj->do_Gadget.Height,
  272.               (dobj->do_DefaultTool ? "YES" : "NO"), dobj->do_DefaultTool);
  273.             
  274.             if(type == TYPE_OS35 || type == TYPE_BOTHCOLOR)
  275.             {
  276.           LONG t1 = -1, t2 = -1, fr = 0, w = 0, h = 0, i2, s1, s2;
  277.  
  278.               IconControl(dobj, ICONCTRLA_GetTransparentColor1, &t1, TAG_DONE);
  279.               IconControl(dobj, ICONCTRLA_GetPaletteSize1, &s1, TAG_DONE);
  280.               IconControl(dobj, ICONCTRLA_GetPaletteSize2, &s2, TAG_DONE);
  281.               IconControl(dobj, ICONCTRLA_GetTransparentColor2, &t2, TAG_DONE);
  282.               IconControl(dobj, ICONCTRLA_GetImageData2, &i2, TAG_DONE);
  283.               IconControl(dobj, ICONCTRLA_GetFrameless, &fr, TAG_DONE);
  284.               IconControl(dobj, ICONCTRLA_GetWidth, &w, TAG_DONE);
  285.               IconControl(dobj, ICONCTRLA_GetHeight, &h, TAG_DONE);
  286.  
  287.           Printf("  CI -Width      : %3ld\n  CI -Height     : %3ld\n"
  288.           "  CI -Borderless : %s\n  CI -NumImages  : %3ld\n  CI1-Transparent: ",
  289.           w, h, fr ? "YES" : "NO",i2 ? 2 : 1);
  290.           
  291.           Printf(t1 == -1 ? "NO" : "%3ld", t1);
  292.           Printf("\n  CI1-NumColors  : %3ld\n", s1);
  293.           if(i2)
  294.           {
  295.                 Printf("  CI2-Transparent: ");
  296.             Printf(t2 == -1 ? "NO" : "%3ld", t2);
  297.                 Printf("\n  CI2-NumColors  : %3ld\n", s2);
  298.               }
  299.             }
  300.  
  301.             Printf("  TT: (%s)\n", t2);
  302.  
  303.             if((tt = (STRPTR *) dobj->do_ToolTypes))
  304.             {
  305.               while(*tt)
  306.               {
  307.                 if((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT))
  308.                   break;
  309.                 else
  310.                   Printf("  %s\n", *(tt++));
  311.               }
  312.             }
  313.             ret = RETURN_OK;
  314.  
  315. #ifdef DEBUG
  316.   Printf("NextGadget:   $%08lx\n", dobj->do_Gadget.NextGadget);
  317.   Printf("LeftEdge:     %4ld\n", dobj->do_Gadget.LeftEdge);
  318.   Printf("TopEdge:      %4ld\n", dobj->do_Gadget.TopEdge);
  319.   Printf("Width:        %4ld\n", dobj->do_Gadget.Width);
  320.   Printf("Height:       %4ld\n", dobj->do_Gadget.Height);
  321.   Printf("Flags:        $%04lx\n", dobj->do_Gadget.Flags);
  322.   Printf("Activation:   $%04lx\n", dobj->do_Gadget.Activation);
  323.   Printf("GadgetType:   %4ld\n", dobj->do_Gadget.GadgetType);
  324.   Printf("GadgetRender: $%08lx\n", dobj->do_Gadget.GadgetRender);
  325.   Printf("SelectRender: $%08lx\n", dobj->do_Gadget.SelectRender);
  326.   Printf("GadgetText:   $%08lx\n", dobj->do_Gadget.GadgetText);
  327.   Printf("MutualExclude:%4ld\n", dobj->do_Gadget.MutualExclude);
  328.   Printf("SpecialInfo:  $%08lx\n", dobj->do_Gadget.SpecialInfo);
  329.   Printf("GadgetID:     %4ld\n", dobj->do_Gadget.GadgetID);
  330.   Printf("UserData:     $%08lx\n", dobj->do_Gadget.UserData);
  331.   if(dobj->do_Gadget.Flags & GFLG_GADGIMAGE)
  332.   {
  333.     struct Image *i;
  334.     
  335.     i = (struct Image *) dobj->do_Gadget.GadgetRender;
  336.     Printf("LeftEdge:     %4ld\n", i->LeftEdge);
  337.     Printf("TopEdge:      %4ld\n", i->TopEdge);
  338.     Printf("Width:        %4ld\n", i->Width);
  339.     Printf("Height:       %4ld\n", i->Height);
  340.     Printf("Depth:        %4ld\n", i->Depth);
  341.     Printf("ImageData:    $%08lx\n", i->ImageData);
  342.     Printf("PlanePick:    %2ld\n", i->PlanePick);
  343.     Printf("PlaneOnOff:   %2ld\n", i->PlaneOnOff);
  344.     Printf("NextImage:    $%08lx\n", i->NextImage);
  345.   }
  346. #endif
  347.           }
  348.           else
  349.           {
  350.             if(args->copyiconimage)
  351.             {
  352.               if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY != NO_ICON_POSITION)
  353.               {
  354.                 dobj->do_CurrentX += (dobj->do_Gadget.Width>>1) - (dobjsrc->do_Gadget.Width>>1);
  355.                 dobj->do_CurrentY += dobj->do_Gadget.Height - dobjsrc->do_Gadget.Height;
  356.                 /* 'down middle position' of gadget should be same after image copy */
  357.               }
  358.               dobj->do_Gadget = dobjsrc->do_Gadget;       /* copy gadget structures */
  359.             }
  360.  
  361.             if(args->copytooltypes || args->copynewicon)
  362.             {
  363.               s = 0;
  364.               if((tt = (STRPTR *) (args->copytooltypes ? dobjsrc : dobj)->do_ToolTypes))
  365.               {
  366.                  while(*tt && !((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT)))
  367.                   tooltypes[s++] = *(tt++);
  368.               }
  369.               if((tt = (STRPTR *) (args->copynewicon ? dobjsrc : dobj)->do_ToolTypes))
  370.               {
  371.                 while(*tt && !((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT)))
  372.                   ++tt;
  373.                 while(*tt)
  374.                   tooltypes[s++] = *(tt++);
  375.               }
  376.               dobj->do_ToolTypes = (char **) (s ? tooltypes : 0);
  377.             }
  378.  
  379.             if(args->seticontype)
  380.             {
  381.               s = 0;
  382.  
  383.               while(++s <= WBAPPICON && stricmp(IconTypeRecog[s], args->seticontype))
  384.                 ;
  385.               if(s <= WBAPPICON)
  386.                 dobj->do_Type = s;
  387.  
  388.               if(!(dobj->do_DrawerData && (dobj->do_Type == WBDISK ||
  389.               dobj->do_Type == WBGARBAGE || dobj->do_Type == WBDRAWER)))
  390.                 dobj->do_DrawerData = dobjdrw->do_DrawerData;
  391.             }
  392.  
  393.             if(args->remap)
  394.             {
  395.               RemapImage((struct Image *) dobj->do_Gadget.GadgetRender);
  396.               if(dobj->do_Gadget.SelectRender)
  397.                 RemapImage((struct Image *) dobj->do_Gadget.SelectRender);
  398.             }
  399.  
  400.             if(args->setbitplanes)
  401.             {
  402.               ((struct Image *) dobj->do_Gadget.GadgetRender)->Depth = *args->setbitplanes;
  403.               if(dobj->do_Gadget.SelectRender)
  404.                 ((struct Image *) dobj->do_Gadget.SelectRender)->Depth = *args->setbitplanes;
  405.             }
  406.  
  407.             if(args->copydeftool)         dobj->do_DefaultTool = dobjsrc->do_DefaultTool;
  408.             if(args->copyicontype)        dobj->do_Type = dobjsrc->do_Type;
  409.             if(args->copystacksize)       dobj->do_StackSize = dobjsrc->do_StackSize;
  410.             if(args->copydrawerdata)      dobj->do_DrawerData = dobjsrc->do_DrawerData;
  411.                   if(args->setxpos)             dobj->do_CurrentX = *args->setxpos;
  412.             if(args->setypos)             dobj->do_CurrentY = *args->setypos;
  413.             if(args->setstacksize)        dobj->do_StackSize = *args->setstacksize;
  414.             if(args->setdeftool)          dobj->do_DefaultTool = args->setdeftool;
  415.             if(args->unsnap)              dobj->do_CurrentX = dobj->do_CurrentY = NO_ICON_POSITION;
  416.             if(args->killstacksize)       dobj->do_StackSize = 0;
  417.             if(args->killdeftool)         dobj->do_DefaultTool = 0;
  418.  
  419.             if(args->killdrawerdata)
  420.             {
  421.                     dobj->do_DrawerData = dobjdrw->do_DrawerData;
  422.               if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE && dobj->do_Type != WBDRAWER)
  423.                 dobj->do_DrawerData = 0;
  424.             }
  425.  
  426.             if(args->killnewicon && (tt = (STRPTR *) dobj->do_ToolTypes))
  427.             {
  428.               while(*tt)
  429.               {
  430.                 if((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT))
  431.                   *tt = 0;
  432.                 else
  433.                   ++tt;
  434.               }
  435.             }
  436.  
  437.             if(args->killtooltypes && (tt = (STRPTR *) dobj->do_ToolTypes))
  438.             {
  439.               s = 0;
  440.               while(*tt && !((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT)))
  441.                 ++tt;
  442.               while(*tt)
  443.                 tooltypes[s++] = *(tt++);
  444.               dobj->do_ToolTypes = (char **) (s ? tooltypes : 0);
  445.             }
  446.  
  447.             if(args->copycoloricon)
  448.             {
  449.               LONG t1=-1, t2=-1, s1=0, s2=0, fr=0, w=0, h=0, wo = 0, ho = 0;
  450.               struct ColorRegister *c1=0, *c2=0;
  451.               UBYTE *i1=0, *i2=0;
  452.               UBYTE as=0;
  453.  
  454.               IconControl(dobjsrc, ICONCTRLA_GetTransparentColor1, &t1, TAG_DONE);
  455.               IconControl(dobjsrc, ICONCTRLA_GetTransparentColor2, &t2, TAG_DONE);
  456.               IconControl(dobjsrc, ICONCTRLA_GetPalette1, &c1, TAG_DONE);
  457.               IconControl(dobjsrc, ICONCTRLA_GetPalette2, &c2, TAG_DONE);
  458.               IconControl(dobjsrc, ICONCTRLA_GetPaletteSize1, &s1, TAG_DONE);
  459.               IconControl(dobjsrc, ICONCTRLA_GetPaletteSize2, &s2, TAG_DONE);
  460.               IconControl(dobjsrc, ICONCTRLA_GetImageData1, &i1, TAG_DONE);
  461.               IconControl(dobjsrc, ICONCTRLA_GetImageData2, &i2, TAG_DONE);
  462.               IconControl(dobjsrc, ICONCTRLA_GetFrameless, &fr, TAG_DONE);
  463.               IconControl(dobjsrc, ICONCTRLA_GetAspectRatio, &as, TAG_DONE);
  464.               IconControl(dobjsrc, ICONCTRLA_GetWidth, &w, TAG_DONE);
  465.               IconControl(dobjsrc, ICONCTRLA_GetHeight, &h, TAG_DONE);
  466.  
  467.               if(!IconControl(dobj, ICONCTRLA_GetWidth, &wo, TAG_DONE))
  468.                 wo =dobj->do_Gadget.Width;
  469.               if(!IconControl(dobj, ICONCTRLA_GetHeight, &ho, TAG_DONE))
  470.                 ho = dobj->do_Gadget.Height;
  471.               if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY != NO_ICON_POSITION)
  472.               {
  473.                 dobj->do_CurrentX += (wo>>1) - (w>>1);
  474.                 dobj->do_CurrentY += ho - h;
  475.                 /* 'down middle position' of gadget should be same after image copy */
  476.               }
  477.  
  478.               IconControl(dobj, ICONCTRLA_SetAspectRatio, as, TAG_DONE);
  479.               IconControl(dobj, ICONCTRLA_SetWidth, w, TAG_DONE);
  480.               IconControl(dobj, ICONCTRLA_SetHeight, h, TAG_DONE);
  481.               IconControl(dobj, ICONCTRLA_SetPaletteSize1, s1, TAG_DONE);
  482.               IconControl(dobj, ICONCTRLA_SetPaletteSize2, s2, TAG_DONE);
  483.               IconControl(dobj, ICONCTRLA_SetPalette1, c1, TAG_DONE);
  484.               IconControl(dobj, ICONCTRLA_SetPalette2, c2, TAG_DONE);
  485.               IconControl(dobj, ICONCTRLA_SetImageData1, i1, TAG_DONE);
  486.               IconControl(dobj, ICONCTRLA_SetImageData2, i2, TAG_DONE);
  487.               IconControl(dobj, ICONCTRLA_SetFrameless, fr, TAG_DONE);
  488.               IconControl(dobj, ICONCTRLA_SetTransparentColor1, t1, TAG_DONE);
  489.               IconControl(dobj, ICONCTRLA_SetTransparentColor2, t2, TAG_DONE);
  490.               type = TYPE_OS35;
  491.             }
  492.  
  493.             if(args->mwb2ci || args->ii2ci) /* made from code by Olaf Barthel */
  494.             {
  495.               struct Image *image[2];
  496.               struct GfxBase *GfxBase;
  497.  
  498.               image[0] = (struct Image *)dobj->do_Gadget.GadgetRender;
  499.               image[1] = (struct Image *)dobj->do_Gadget.SelectRender;
  500.  
  501.               if((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37)))
  502.               {
  503.                 struct RastPort rp;
  504.                 struct BitMap bm;
  505.                 LONG pixelsPerImage, pageSize, x, y, i, j;
  506.                 UBYTE *p;
  507.                 PLANEPTR plane;
  508.  
  509.                 for(j = 0; j < 2 && image[j]; ++j)
  510.                 {
  511.                   pixelsPerImage = (LONG)image[j]->Width * (LONG)image[j]->Height;
  512.                   if((imageBuffer[j] = AllocVec(pixelsPerImage, MEMF_ANY)))
  513.                   {
  514.                     if(image[j]->Depth > 3)
  515.                       image[j]->Depth = 3;
  516.  
  517.                     InitRastPort(&rp);
  518.                     rp.BitMap = &bm;
  519.  
  520.                     memset(&bm, 0, sizeof(struct BitMap));
  521.                     bm.BytesPerRow = RASSIZE(image[j]->Width,1);
  522.                     bm.Rows        = image[j]->Height;
  523.                     bm.Depth       = image[j]->Depth;
  524.                     pageSize = RASSIZE(image[j]->Width,image[j]->Height);
  525.                     plane = (PLANEPTR)image[j]->ImageData;
  526.  
  527.                     for(i = 0; i < image[j]->Depth; ++i)
  528.                     {
  529.                       bm.Planes[i] = plane;
  530.                       plane += pageSize;
  531.                     }
  532.  
  533.                     p = imageBuffer[j];
  534.                     for(y = 0; y < image[j]->Height ; y++)
  535.                     {
  536.                       for(x = 0; x < image[j]->Width ; x++)
  537.                         (*p++) = ReadPixel(&rp,x,y);
  538.                     }
  539.                   }
  540.                 }
  541.  
  542.         p = (UBYTE *) (args->mwb2ci ? MagicWBPalette : Default8Palette);
  543.  
  544.                 IconControl(dobj, ICONCTRLA_SetWidth, image[0]->Width, ICONCTRLA_SetHeight, image[0]->Height,
  545.                 ICONCTRLA_SetAspectRatio, PACK_ICON_ASPECT_RATIO(1,1), ICONCTRLA_SetImageData1, imageBuffer[0],
  546.                 ICONCTRLA_SetPaletteSize1, 1<<(image[0]->Depth), ICONCTRLA_SetPalette1, p, TAG_DONE);
  547.  
  548.                 if(image[1])
  549.                 {
  550.                   IconControl(dobj, ICONCTRLA_SetImageData2, imageBuffer[1], ICONCTRLA_SetPaletteSize2,
  551.                   1<<(image[1]->Depth), ICONCTRLA_SetPalette2, p, TAG_DONE);
  552.                 }
  553.                 type = TYPE_OS35;
  554.                 CloseLibrary((struct Library *) GfxBase);
  555.               }
  556.             } /* args->mwb2ci */
  557.  
  558.         if(os35mode)
  559.         {
  560.           if(args->settransparent1) IconControl(dobj, ICONCTRLA_SetTransparentColor1, *args->settransparent1, TAG_DONE);
  561.           if(args->settransparent2) IconControl(dobj, ICONCTRLA_SetTransparentColor2, *args->settransparent2, TAG_DONE);
  562.         }
  563.  
  564.             if(args->killiconimage)
  565.             {
  566.               if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY != NO_ICON_POSITION
  567.               && type == TYPE_STANDARD)
  568.               {
  569.                 dobj->do_CurrentX += (dobj->do_Gadget.Width>>1) - 2;
  570.                 dobj->do_CurrentY += dobj->do_Gadget.Height - 5;
  571.                 /* 'down middle position' of gadget should be same after image replace */
  572.               }
  573.               dobj->do_Gadget.LeftEdge = dobj->do_Gadget.TopEdge = 50;
  574.               dobj->do_Gadget.Width = dobj->do_Gadget.Height = 4;
  575.               dobj->do_Gadget.Flags = GFLG_GADGIMAGE;
  576.               dobj->do_Gadget.GadgetRender = (APTR) &KIIImage;
  577.               dobj->do_Gadget.SelectRender = 0;
  578.             }
  579.  
  580.             if(args->optimize)
  581.             {
  582.               if(dobj->do_Type != WBDISK && dobj->do_Type != WBPROJECT)
  583.                 dobj->do_DefaultTool = 0;
  584.               if(dobj->do_Type != WBPROJECT && dobj->do_Type != WBTOOL)
  585.                 dobj->do_ToolTypes = 0;
  586.               if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE && dobj->do_Type != WBDRAWER)
  587.                 dobj->do_DrawerData = 0;
  588.               if(dobj->do_ToolTypes && !(*dobj->do_ToolTypes))
  589.                 dobj->do_ToolTypes = 0;
  590.             }
  591.  
  592.             if(os35mode)
  593.             {
  594.               if(PutIconTags(args->icon, dobj, ICONPUTA_NotifyWorkbench, TRUE, ICONPUTA_PreserveOldIconImages,
  595.               FALSE, args->killnewicon ? ICONPUTA_DropNewIconToolTypes : TAG_IGNORE, TRUE, 
  596.               args->killcoloricon ? ICONPUTA_DropChunkyIconImage : TAG_IGNORE, TRUE,
  597.               args->optimize ? ICONPUTA_OptimizeImageSpace : TAG_IGNORE, TRUE,
  598.               args->killiconimage ? ICONPUTA_DropPlanarIconImage :  TAG_IGNORE, TRUE, TAG_DONE))
  599.                 ret = RETURN_OK;
  600.             }
  601.             else if(PutDiskObject(args->icon, dobj))
  602.               ret = RETURN_OK;
  603.           } /* !args->view */
  604.  
  605.           if(imageBuffer[0])
  606.             FreeVec(imageBuffer[0]);
  607.           if(imageBuffer[1])
  608.             FreeVec(imageBuffer[1]);
  609.           FreeVec(tooltypes);
  610.         } /* allocate tooltype temp array */
  611.         if(dobjsrc)
  612.           FreeDiskObject(dobjsrc);
  613.       } /* open reficon */
  614.       FreeDiskObject(dobjdrw);
  615.     } /* open drawer disk object */
  616.     FreeDiskObject(dobj);
  617.   } /* open DiskObject */
  618.   return ret;
  619. }
  620.  
  621. LONG main(void)
  622. {
  623.   struct RDArgs *rda;
  624.   struct Args args;
  625.   struct Args argse;
  626.   LONG ret = RETURN_FAIL, os35;
  627.  
  628.   memset(&args, 0, sizeof(struct Args));
  629.   if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  630.   {
  631.     struct Library *IconBase;
  632.     if((IconBase = OpenLibrary("icon.library", 37)))
  633.     {
  634.       ULONG argerr = 0;
  635.  
  636.       TESTGROUP(0,                args.killcoloricon,   args.copycoloricon);
  637.       TESTGROUP(0,                args.killdrawerdata,  args.copydrawerdata);
  638.       TESTGROUP(args.setdeftool,  args.killdeftool,     args.copydeftool);
  639.       TESTGROUP(0,                args.killiconimage,   args.copyiconimage);
  640.       TESTGROUP(args.seticontype, 0,                    args.copyicontype);
  641.       TESTGROUP(0,                args.killnewicon,     args.copynewicon);
  642.       TESTGROUP(args.setstacksize,args.killstacksize,   args.copystacksize);
  643.       TESTGROUP(0,                args.killtooltypes,   args.copytooltypes);
  644.  
  645.       TESTGROUP(args.ni2ci,       args.ii2ci,           args.mwb2ci);
  646.  
  647.       if(args.makeci && (args.ii2ci || args.mwb2ci || args.ni2ci))
  648.         ++argerr;
  649.  
  650.       if(args.unsnap && (args.setxpos || args.setypos))
  651.         ++argerr;
  652.  
  653.       if(IconBase->lib_Version < 44 && (args.ni2ci || args.ii2ci || args.killcoloricon || args.copycoloricon
  654.       || args.mwb2ci))
  655.       {
  656.         Printf("You need icon.library V44 or better for the CI options.\n");
  657.        ++argerr;
  658.       }
  659.  
  660.       if((args.ni2ci || args.mwb2ci || args.ii2ci) && (args.killcoloricon || args.copycoloricon))
  661.         ++argerr;
  662.  
  663.       if(args.killnewicon && args.ni2ci)
  664.         ++argerr;
  665.       
  666.       if(!args.reficon && (args.copydrawerdata || args.copydeftool || args.copyiconimage || args.copyicontype ||
  667.       args.copynewicon || args.copystacksize || args.copytooltypes))
  668.         ++argerr;
  669.  
  670.       if(argerr || (args.setbitplanes && args.killiconimage))
  671.         SetIoErr(ERROR_TOO_MANY_ARGS);
  672.       else
  673.       {
  674.         ULONG s;
  675.  
  676.         s = strlen(args.icon);
  677.         if(!strncmp(args.icon+s-5, ".info",5))
  678.           args.icon[s-5] = 0;
  679.         if(args.reficon)
  680.         {
  681.           s = strlen(args.reficon);
  682.           if(!strncmp(args.reficon+s-5, ".info",5))
  683.           args.reficon[s-5] = 0;
  684.         }
  685.  
  686.         os35 = IconBase->lib_Version >= 44 ? 1 : 0;
  687.         if(!(ret = dowork(&args, IconBase, os35)))
  688.         {
  689.           if(!args.view && os35 && args.copynewicon)
  690.           {
  691.             memset(&argse, 0, sizeof(struct Args));
  692.             argse.icon = args.icon;
  693.             argse.reficon = args.reficon;
  694.             argse.copynewicon = 1;
  695.             ret = dowork(&argse, IconBase, 0);
  696.           }
  697.           if(!args.view && !args.showtype && args.ni2ci)
  698.           {
  699.             struct DiskObject *dobj;
  700.  
  701.             if((dobj = GetIconTags(args.icon, TAG_DONE)))
  702.             {
  703.               if(PutIconTags(args.icon, dobj, ICONPUTA_NotifyWorkbench, TRUE,
  704.               ICONPUTA_DropNewIconToolTypes, TRUE, TAG_DONE));
  705.                 ret = RETURN_OK;
  706.               FreeDiskObject(dobj);
  707.             }
  708.           }
  709.         }
  710.       } /* argument checks */
  711.       CloseLibrary(IconBase);
  712.     } /* open icon.library */
  713.     FreeArgs(rda);
  714.   } /* ReadArgs */
  715.   if(ret)
  716.     PrintFault(IoErr(), 0);
  717.   return ret;
  718. }
  719.  
  720.